package com.skyable.device.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.skyable.common.common.ServiceResult;
import com.skyable.device.entity.DeviceAuthLog;
import com.skyable.device.mapper.DeviceAuthLogMapper;
import com.skyable.device.service.IDeviceAuthLogService;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * @author GaoYuan
 * @title: DeviceAuthLogServiceImpl
 * @projectName private-cloud
 * @description: TODO
 * @date 2021/7/318:44
 */
public class DeviceAuthLogServiceImpl extends ServiceImpl<DeviceAuthLogMapper,DeviceAuthLog> implements IDeviceAuthLogService {

    @Override
    public ServiceResult<IPage<DeviceAuthLog>> getDeviceLogList(Long domainId, DeviceAuthLog deviceAuthLog, Integer page, Integer limit) {
        ServiceResult<IPage<DeviceAuthLog>> serviceResult = new ServiceResult<>();
        IPage<DeviceAuthLog> deviceAuthLogIPage = new Page<>(page,limit);
        QueryWrapper<DeviceAuthLog> queryWrapper = new QueryWrapper<>();
        queryWrapper.setEntity(deviceAuthLog);
        IPage<DeviceAuthLog> authLogIPage = baseMapper.selectPage(deviceAuthLogIPage, queryWrapper);
        serviceResult.setResult(authLogIPage);
        return serviceResult;
    }

    @Override
    public ServiceResult<Boolean> deleteDeviceLogList(Long[] logIds) {
        ServiceResult<Boolean> serviceResult = new ServiceResult<>();
        if(logIds != null && logIds.length > 0) {
            int result = baseMapper.deleteBatchIds(Arrays.asList(logIds));
            serviceResult.setResult(result > 0);
        }
        return serviceResult;
    }

}
